
<div class="space-4"></div>
<!-- 判断表单是否发生过更改的token -->
<input type="hidden" id="form_token" value="0"/>
<!-- 乐观锁控制 -->
<input type="hidden" id="_version" name="VERSION" value="0">

@ if(isEmpty(keys)) {
<input type="hidden" id="_${key!'id'}" name="${table!}.${key!'id'}" value=""/>
@ } else {
@for(k in keys) {
<input type="hidden" id="${k.table!}_${k.key!'id'}" name="${k.table!}.${k.key!'id'}" value=""/>
@}
@ }
<table class="table table-bordered" style="margin-bottom:0px;">
	@ for(x in col){
	@ if(!isEmpty(x.title)) {
	<tr>
		<td colspan="4"><span style="font-size:15px;">${x.title!}</span>
			@ if(!isEmpty(x.small)) {
			<small>
				<i class="ace-icon fa fa-angle-double-right">
					${x.small!}
				</i>
			</small>
			@ }
		</td>
	<tr>
		@ } else {
		@	var display = (func.like(x.type,"hidden")) ? "style='display:none'" : "";
		@   var placeholder = (!isEmpty(x.placeholder)) ? x.placeholder : ("暂无"+x.name);
		@	if(x.newline){
	<tr ${display!}>
		@	}
		@			var token = (x.token!true) ? "token_" : "";
		<td style="vertical-align: middle !important;width:15%;text-align:right;"> ${x.name!} </td>
		@ var tdstyle = (x.length >= 5) ? "colspan='3' style='width:85%;padding:0;'" : "style='width:35%;padding:0;'";
		<td ${tdstyle}>
			@			if(x.type == "text" || x.type == "number" || x.type == "tel" || x.type == "email" || x.type == "url" || x.type == "qq" || x.type == "unionpay" || x.type == "credit" || x.type == "idcard") {
			<input type="${x.type!'text'}" id="_${x.index!}" name="${token}${table!x.table}.${x.index!}" ${x.required!} ${x.disabled!} value="${x.value!}" placeholder="${placeholder!}" class="form-control" />
			@			}
			@			else if(x.type == "double") {
			<input type="${x.type!'text'}" id="_${x.index!}" name="${token}${table!x.table}.${x.index!}" ${x.required!} ${x.disabled!} value="${x.value!}" placeholder="${placeholder!}" class="form-control" />
			@			}
			@			else if(func.like(x.type, "hidden")) {
			<input type="${x.type!'hidden'}" id="_${x.index!}" name="${table!x.table}.${x.index!}"  value="${x.value!}" class="form-control" />
			@			}
			@			else if(x.type == "textarea") {
			<textarea id="_${x.index!}" style="height:${x.height!'200px'}" name="${token}${table!x.table}.${x.index!}" ${x.required!} ${x.disabled!} value="${x.value!}" placeholder="${placeholder!}" class="form-control"></textarea>
			@			}
			@			else if(x.type == "image") {
			<img id="_${x.index!}" data-type="image" data-auto="${x.auto!}" style="padding:2px; border:1px solid #ccc;cursor:pointer;width:${x.width!'168px'};height:${x.height!'110px'};" name="${table!x.table}.${x.index!}" src="${x.src!}"></img>
			@			}
			@			else if(func.like(x.type, "select_")) {
			@                var num = strutil.replace(x.type, "select_", "");
			<blade:select code="${num}" name="${table!x.table}.${x.index!}" value="${x.value!}" type="dict" tail="${x.tail!}" token="${token}" intercept="${x.intercept!}" required="${x.required!}"/>
			@			}
			@			else if(func.like(x.type,"combo_")) {
			@                var num = strutil.replace(x.type, "combo_", "");
			<blade:combo id="${x.index!}" code="${num}" name="${table!x.table}.${x.index!}" value="${x.value!0}" type="dict" required="${x.required!}" placeholder="${placeholder}"/>
			@			}
			@			else if(func.like(x.type, "dropdown_")) {
			@                var num = strutil.replace(x.type, "dropdown_", "");
			<blade:dropdown code="${num}" name="${table!x.table}.${x.index!}" value="${x.value!}" type="dict" tail="${x.tail!}" intercept="${x.intercept!}" required="${x.required!}"/>
			@			}
			@			else if(x.type == "kindeditor") {
			<blade:kindeditor value="${x.value!}" id="_${x.index}" name="${table!x.table}.${x.index!}" height="${x.height!'200px'}" token="${token}" required="${x.required!}" />
			@			}
			@			else if(x.type == "selectDiy") {
			<blade:select  name="${table!x.table}.${x.index!}" value="${x.value!}" type="diy" source="${x.source!}" tail="${x.tail!}" token="${token}" intercept="${x.intercept!}" required="${x.required!}"/>
			@			}
			@			else if(x.type == "comboDiy") {
			<blade:combo id="${x.index!}"  name="${table!x.table}.${x.index!}" value="${x.value!0}" type="diy" source="${x.source!}" required="${x.required!}" placeholder="${placeholder}"/>
			@			}
			@			else if(x.type == "dropdownDiy") {
			<blade:dropdown  name="${table!x.table}.${x.index!}" value="${x.value!}" type="diy" source="${x.source!}" tail="${x.tail!}" token="${token}" intercept="${x.intercept!}" required="${x.required!}"/>
			@			}
			@			else if(x.type == "selectDept") {
			<blade:select  name="${table!x.table}.${x.index!}" value="${x.value!}" type="dept" tail="${x.tail!}" token="${token}" intercept="${x.intercept!}" required="${x.required!}"/>
			@			}
			@			else if(x.type == "dropdownDept") {
			<blade:dropdown  name="${table!x.table}.${x.index!}" value="${x.value!}" type="dept" tail="${x.tail!}" token="${token}" intercept="${x.intercept!}" required="${x.required!}"/>
			@			}
			@			else if(x.type == "selectRole") {
			<blade:select  name="${table!x.table}.${x.index!}" value="${x.value!}" type="role" tail="${x.tail!}" token="${token}" intercept="${x.intercept!}" required="${x.required!}"/>
			@			}
			@			else if(x.type == "dropdownRole") {
			<blade:dropdown  name="${table!x.table}.${x.index!}" value="${x.value!}" type="role" tail="${x.tail!}" token="${token}" intercept="${x.intercept!}" required="${x.required!}"/>
			@			}
			@			else if(x.type == "selectUser") {
			<blade:select  name="${table!x.table}.${x.index!}" value="${x.value!}" type="user" tail="${x.tail!}" token="${token}" intercept="${x.intercept!}" required="${x.required!}"/>
			@			}
			@			else if(x.type == "dropdownUser") {
			<blade:dropdown  name="${table!x.table}.${x.index!}" value="${x.value!}" type="user" tail="${x.tail!}" token="${token}" intercept="${x.intercept!}" required="${x.required!}"/>
			@			}
			@			else if(x.type == "checkbox") {
			<blade:checkbox id="_${x.index!}" name="${table!x.table}.${x.index!}" checked="${x.checked!}" disabled="${x.disabled!}" />
			@			}
			@			else if(x.type == "checkbox2") {
			<blade:checkbox2 id="_${x.index!}" name="${table!x.table}.${x.index!}" checked="${x.checked!}" disabled="${x.disabled!}" />
			@			}
			@			else if(x.type == "date") {
			<blade:date id="_${x.index!}" name="${table!x.table}.${x.index!}" value="${x.value!}" format="${x.format!}" token="${token}" required="${x.required!}" disabled="${x.disabled!}" placeholder="${x.placeholder!'请选择日期'}"/>
			@			}
			@			else if(x.type == "laydate") {
			<blade:laydate id="_${x.index!}" name="${table!x.table}.${x.index!}" value="${x.value!}" format="${x.format!}" token="${token}" required="${x.required!}" disabled="${x.disabled!}" placeholder="${x.placeholder!'请选择日期'}"/>
			@			}
			@			else if(x.type == "imgupload") {
			<blade:imgupload id="_${x.index!}" name="${table!x.table}.${x.index!}" auto="${x.auto!}" />
			@			}
			@			else if(x.type == "fileupload") {
			<blade:fileupload  id="_${x.index!}" name="${table!x.table}.${x.index!}"/>
			@			}
			@			else if(x.type == "file") {
			<blade:file  id="_${x.index!}" name="${table!x.table}.${x.index!}"/>
			@			}
			@			else if(func.like(x.type, "opentree")) {
			<blade:opentree x="${x}" />
			@			}
			@			else if(func.like(x.type,"combotree")) {
			<blade:combotree  id="_${x.index!}" name="${table!x.table}.${x.index!}" value="${x.value!}" type="${x.type!}" source="${x.source!}" check="${x.check!}" treeId="${x.treeId!}" intercept="${x.intercept!}" where="${x.where!}" ext="${x.ext!}" width="${x.width!}" height="${x.height!}" token="${token}" readonly="${x.readonly!}" required="${x.required!}" placeholder="${x.placeholder!'输入后请按回车搜索'}" autoInit="false" fix="true"/>
			@			}
			@			else if(x.type == "span") {
			<span id="_${x.index!}" class="form-control" style="border:0px;">${x.value!}</span>
			@			}
			@			else if(x.type == "password") {
			<input type="password" id="_${x.index!}" name="${table!x.table}.${x.index!}" ${x.required!} ${x.disabled!} value="${x.value!}" placeholder="${placeholder!}" class="form-control" />
			@			}
			@			else {
			<input type="text" id="_${x.index!}" name="${token}${table!x.table}.${x.index!}" ${x.required!} ${x.disabled!} value="${x.value!}" placeholder="${placeholder!}" class="form-control" />
			@			}
		</td>
		@			if(x.length >= 5){
	</tr>
	@			}

	@ 	if(!x.newline){
	</tr>
	@	}
	@}
	@ }
</table>
<script	type="text/javascript">
	$(function(){
		var _model = ${model!"'error'"};
		var _keys = switchBeetl();
		if(_model == "error"){
			layer_alert("读取数据失败!", "error");
			return;
		}
		$("input, textarea").bind("focus", function(){
			var _name = $(this).attr("name").replace("token_", "");
			$(this).attr("name", _name);
			$("#form_token").val(1);
		});
		for(var x in _model){
			var $x = $("#_" + x);

			if(_model[x] != null && $x.attr("data-type") == "image"){
				var src = $("#_"+x).attr("data-auto") + _model[x];
				$x.attr("src",src);
				$x.bind("click",function(){
					window.open($(this).attr("src"));
				});
			}
			else if(_model[x] != null && $x.attr("data-type") == "imgupload"){
				var id = _model[x];
				$x.val(id);
				initImgUpload(id);
			}
			else if(_model[x] != null && $x.attr("data-type") == "fileupload"){
				var ids = _model[x];
				$x.val(ids);
				eval("_" + x + "_initFileUpload('" + ids + "', 'edit')");
			}
			else if(_model[x] != null && $x.attr("data-type") == "opentree"){
				var ids = _model[x];
				$x.val(ids);
				initOpenTree(ids);
			}
			else if(_model[x] != null && $x.attr("data-type") == "combotree"){
				var ids = _model[x];
				$x.val(ids);
				eval("initComboTree_" + x + "_ipt('" + ids + "')");
				eval("initComboTreeName_" + x + "_ipt('" + ids + "')");
			}
			else if(_model[x] != null && $("#_" + x + "_chb").attr("type") == "checkbox"){
				if(_model[x] == "1"){
					$("#_"+x+"_chb").attr("checked","checked");
					$x.val(_model[x]);
				}
				else{
					$("#_"+x+"_chb").removeAttr("checked");
				}
			}
			else if($x.is("span")){
				var _x = _model[x];
				if(_x === null || _x === ""){
					_x = "请选择";
				}
				$x.html(_x);
			}
			else if(_model[x] != null && $x.attr("type")!="autohidden"){
				$x.val(_model[x]);
			}
		}

		for(var k in _keys){
			var id = _keys[k].table + "_" + _keys[k].key;
			$("#" + id).val(_model[id]);
		}

	});

	//beetljson转json格式
	function switchBeetl(){
		var _keys=${keyList!"'true'"};
		if(_keys=="true"){
			_keys="${keys!}";
			_keys=_keys.replace(/=/g,":").replace(/{/g,"{'").replace(/}/g,"'}").replace(/:/g,"':'").replace(/, /g,"','");
			_keys=_keys.replace(/}','{/g,"},{");
			_keys=eval(_keys);
		}
		return _keys;
	}
</script>
<div class="space-4"></div>
<style>
	.form-control ,textarea,select,input[type="text"],input[type="password"],input[type="datetime"],input[type="datetime-local"],input[type="date"],input[type="month"],input[type="time"],input[type="week"],input[type="number"],input[type="email"],input[type="url"],input[type="search"],input[type="tel"],input[type="color"] {
		border-width: 0px;
		background-color:#fcfcfc;
	}
	table {
		background-color:#f5f5f5;
	}
	.ke-container {
		border-width: 0px;
	}
	.ke-input-text {
		background-color: #f1f1f1 !important;
	}
</style>